package com.java.tutorials.jdk7.fileoperation;
import com.java.tutorials.Constants;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
/**
 * Created by xuzhike on 2016/1/25.
 * http://www.java2s.com/Code/Java/JDK-7/Createnewfileandappendbytearraytoit.htm
 * Create new file and append byte array to it
 */
public class Createnewfileandappendbytearraytoit {
    public static void main(String[] args) throws IOException {
        Path path = Paths.get(Constants.TEST_FILE_WITH_PATH);
        byte[] contents = Files.readAllBytes(path);

        Path newPath = Paths.get(Constants.TEST_PATH+"test3.txt");
        byte[] newContents = "aaa".getBytes();
        Files.write(newPath, contents, StandardOpenOption.CREATE);
        Files.write(newPath, newContents, StandardOpenOption.APPEND);
    }
}
